package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.transformation.editor.model.AtomicTransformation;
import edu.pku.sei.transformation.editor.model.Rule;
import edu.pku.sei.transformation.editor.model.Transformation;

public class RuleDragDropCheckCommand extends Command {
	private Rule rule;
	private AtomicTransformation transformation;

	public RuleDragDropCheckCommand(AtomicTransformation transformation,
			Rule rule) {
		this.rule = rule;
		this.transformation = transformation;
	}

	@Override
	public boolean canExecute() {
		if (rule == null || transformation == null || rule.getOwner() == null
				|| rule.getOwner() == transformation)
			return false;
		else {
			AtomicTransformation owner = rule.getOwner();
			AtomicTransformation t = transformation;
			if (t.getAllRules().contains(rule) && !t.getRules().contains(rule))
				return true;
			else
				return false;
		}
	}
}
